
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>SimpleWalletURL</title>
    <meta id="i18n_pagename" content="message">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <link rel="stylesheet" type="text/css" href="https://static.medishares.net/css/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="https://static.medishares.net/css/common.css?v=2018082901">
    <script src="https://static.medishares.net/js/jquery-3.2.1.min.js"></script>
    <script src="https://static.medishares.net/js/vue.min.js"></script>
    <script src="https://static.medishares.net/js/common.js?v=2018082901"></script>
</head>
<body>
<div class="mds-group">
    <link href="https://static.medishares.net/css/market/qixi2018.css" rel="stylesheet">
<div class="qixi">
  <div class="card" style="text-align:center">
    <a class="confirm" onclick="submitFn()">打开麦子钱包并支付EOS</a>
  </div>
  <div style="clear: both;"></div>
  <ul class="qixi-about">
    <li>
      <h3>该示例展示通过链接打开麦子钱包，并进行支付的DEMO</h3>
      <h3>请使用手机浏览器打开本页面，点击上面的按钮</h3>
      <h3>详细SDK方案查看：<a href="http://doc.mathwallet.org" style="color:#fff">MathWallet SDK</a></h3>
    </li>
  </ul>
</div>

<script type="text/javascript">
var params = {
  "blockchain": "eosio",
  "version": "1.0",
  "protocol": "SimpleWallet",
  "amount": "1.0000",
  "symbol": "EOS",
  "expired": 1546597930,
  "from": "",
  "to": "sendeostoken",
  "dappIcon": "http://www.mathwallet.org/images/download/wallet_cn.png",
  "dappData": "memo",
  "desc": "这是展示在钱包中的描述",
  "action": "transfer",
  "dappName": "MathWalletSDK-Demo",
  "precision": 4,
  "contract": "eosio.token",
  "callback": "mathwalletdemos://mathwalletsdk?action=transfer"
};
var mathURI = "mathwallet://mathwallet.org?param="+JSON.stringify(params);

function submitFn(){
    //判断浏览器
    var u = navigator.userAgent;
    if(/MicroMessenger/gi.test(u)) {
       // 引导用户在浏览器中打开
        alert('点击右上角，选择浏览器中打开');
        return;
    }
    var d = new Date();
    var t0 = d.getTime();
    if(u.indexOf('Android') > -1 || u.indexOf('Linux') > -1){
        //Android
        if(openApp(mathURI)){
         openApp(mathURI);
        }else{
            //由于打开需要1～2秒，利用这个时间差来处理－－打开app后，返回h5页面会出现页面变成app下载页面，影响用户体验
            var delay = setInterval(function(){
                 var d = new Date();
                 var t1 = d.getTime();
                 if( t1-t0<3000 && t1-t0>2000){
                    alert('请下载麦子钱包');
                     window.location.href = "http://mathwallet.org";
                 }
                 if(t1-t0>=3000){
                      clearInterval(delay);
                 }
            },1000);
        }
    }else if(u.indexOf('iPhone') > -1){
        //IOS
        if(openApp(mathURI)){
            openApp(mathURI);
        }else{
            var delay = setInterval(function(){
                var d = new Date();
                var t1 = d.getTime();
                if( t1-t0<3000 && t1-t0>2000){
                    alert('请下载麦子钱包');
                    window.location.href = "http://mathwallet.org";
                }
                if(t1-t0>=3000){
                    clearInterval(delay);
                }
            },1000);
        }
    }
}

function openApp(src) {
  window.location.href = src;

    // 通过iframe的方式试图打开APP，如果能正常打开，会直接切换到APP，并自动阻止a标签的默认行为
     // 否则打开a标签的href链接
     // var ifr = document.createElement('iframe');
     // ifr.src = src;
     // ifr.style.display = 'none';
     // document.body.appendChild(ifr);
     // window.setTimeout(function(){
     //      document.body.removeChild(ifr);
     // },2000);
}
</script>

</div>
</body>
</html>
